var wechat = (function() {
  return {
    /* 正则验证 */
    check: {
      isEmpty: function(obj) {
        if(obj == null || obj == undefined || ("" + obj) == "") {
          return true;
        }
        return false;
      },
      isPhone: function(str) {
        let regu = /^1[3-8][0-9]{9}$/;
        return regu.test(str);
      }
    },
    // 解析url参数
    //@example ?id=12345&a=b
    // @return Object {id:12345,a:b}
    urlParse: function() {
      let url = window.location.search;
      let obj = {};
      let reg = /[?&][^?&]+=[^?&]+/g;
      let arr = url.match(reg);
      if(arr) {
        arr.forEach(item => {
          let tempArr = item.substring(1).split("=");
          let key = decodeURIComponent(tempArr[0]);
          let value = decodeURIComponent(tempArr[1]);
          obj[key] = value;
        })
      }
      return obj;
    },
    //      调用微信接口
    wxAPI: function(jsApi, sendJSON, callback) {
      if(data.responseCode == "000000") {
        console.log('jsApi===' + jsApi);
        wx.config({
          debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
          appId: configParam.appId, // 必填，公众号的唯一标识
          timestamp: data.timestamp, // 必填，生成签名的时间戳
          nonceStr: data.nonceStr, // 必填，生成签名的随机串
          signature: data.signature, // 必填，签名
          jsApiList: jsApi // 必填
        });

        wx.ready(function() {
          callback();
        });
      } else {
        alert(data.responseDesc);
      }

    },
    //loading提示框
    loadingBox: function() {
      var load = $("<div class='masl' id='mask'></div><div id='loading' class='loading-box'></div>");
      load.appendTo(window.document.body);
      $("#mask").css({
        "display": "block",
        "background-color": "rgba(0,0,0,0)"
      });
      var stu = "<div class='loadEffect'>";
      stu += "<span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></div>";
      stu += "<div class='load-str'>正在加载...</div>";
      $("#loading").html(stu);
      setTimeout("umswxapi.closeLoading()", 30000);
    },
    closeLoading: function() {
      $("#loading").remove();
      $("#mask").remove();
    },
  }
})();
/*日期格式化*/
Date.prototype.Format = function(fmt) {
  if(/(y+)/.test(fmt)) {
    fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substring(4 - RegExp.$1.length));
  }
  var o = {
    "M+": this.getMonth() + 1,
    "d+": this.getDate(),
    "h+": this.getHours(),
    "m+": this.getMonth(),
    "s+": this.getSeconds(),
  }
  for(let k in o) {
    if(new RegExp(`(${k})`).test(fmt)) {
      let str = "" + o[k];
      fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : str.substring((str).length))
    }
  }
}